<?php
require_once 'includes/image_resizer.php'; 
require_once 'includes/functions.php'; 
require_once 'includes/class.phpmailer.php';
//print_r($_REQUEST);
$smsg="";
if($_SESSION['user_id_sess']=="") {
	echo "<script type='text/javascript'> window.location='index.php?signin&url=refer'; </script>";
}
@extract($_REQUEST);
if(isset($_REQUEST['submitbutton'])=='Submit')
{	
	$sqlPost="update tbl_users set amazon_email='".$_REQUEST['amazon_email']."'
		  where user_id='".$_SESSION['user_id_sess']."' ";
	$rstPost=mysql_query($sqlPost) or die(mysql_error());	
	$strMessage .="Your amazon payment account has been update successfully<br/>";		
	$withdraw="";
	
	if(mysql_affected_rows()>0) 
	{	
		$smsg="true";
		$postId=mysql_insert_id();					
	}
	else { $smsg="false"; }	
	
}

$sql_comm="SELECT amazon_email FROM tbl_users WHERE user_id =".$_SESSION['user_id_sess']." ";

$rst_comm=mysql_query($sql_comm);
$row_comm=mysql_fetch_array($rst_comm);
if(is_array($row_comm))
{
	$amazon_email=$row_comm['amazon_email'];
}

?>
<style type="text/css">
	#sell-form { border:0px solid #CCC; vertical-align:top; padding:10px; float:left; width:93%; margin:2%; }

	#sell-form label{
	float: left;
	width: 130px;
	font-weight: bold;
	}
	
	#sell-form input, select, textarea{	
	width: 280px;
	margin-bottom: 5px;
	font-size:12px;
	}
	
	#sell-form textarea{
	height: 250px;
	width: 450px;
	font-size:12px
	}
	
	#sell-form #submitbutton{
	margin-left: 130px;
	margin-top: 5px;
	width: 90px;
	}
	
	#sell-form br{
	clear: left;
	}

	
</style>
<script language="javascript" type="text/javascript">
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// whitespace characters
var whitespace = " \t\n\r";
var sEmail = "Email";
var iEmail = "This field must be a valid email address (user@host.domain). Please reenter it now.";
var pEntryPrompt = "Please enter a ";
var pEmail = "valid email address (like foo@bar.com).";
var defaultEmptyOK = false;
function checkEmail (theField, emptyOK)
{   if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;
	else if (!isEmail(theField.value, false)) 
	   return warnInvalid (theField, iEmail);
	else return true;
}
function isEmail (s)
{   if (isEmpty(s)) 
	   if (isEmail.arguments.length == 1) return defaultEmptyOK;
	   else return (isEmail.arguments[1] == true);
   
	// is s whitespace?
	if (isWhitespace(s)) return false;
	
	// there must be >= 1 character before @, so we
	// start looking at character position 1 
	// (i.e. second character)
	var i = 1;
	var sLength = s.length;

	// look for @
	while ((i < sLength) && (s.charAt(i) != "@"))
	{ i++
	}

	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	else i += 2;

	// look for .
	while ((i < sLength) && (s.charAt(i) != "."))
	{ i++
	}

	// there must be at least one character after the .
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	else return true;
}	
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
function isWhitespace (s)
{   var i;

    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }   
    return true;
}
function removeSpaces(string) {
 return string.split(' ').join('');
}	

function checkEmails(inputvalue){	
    var pattern=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;

    if(pattern.test(inputvalue)){         
		return true;   
    }else{   
		return false; 
    }
}

function validateEmail()
{
	var frm=document.frmPost;	
	var strValue=document.frmPost.amazon_email.value;	
	var bReturn=true;
	if(!checkEmails(strValue.toString()))
	{
		alert("Please enter valid email : " + strValue.toString());
		frm.amazon_email.focus();
		bReturn= false;
	}
	return bReturn;
}


</script>
<div id='panel'>
<table width="100%" border="0">
  <tr>
    <td class="contentHeader"><h2>Amazon Payment Email Account</h2></td>
    <td class="contentHeader" align="right">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">
	
	<table width="100%" align="center"  border="0" cellspacing="0">
      <tr>
	  	<td><?php if($strMessage!="") { echo $strMessage; } ?></td>
	  </tr>
      <tr>
        <td height="100">			
		<form name="frmPost" id="frmPost" method="post" action="" enctype="multipart/form-data">    
			  <input type="hidden" name="keyword" id="keyword">
				<div id="sell-form">				
					
					<label for="post_description" style="width:330px;">Add email addresses for future reference </label>
					<p>
					  <input name="amazon_email" id="amazon_email" value="<?php echo $amazon_email;?>" />
					  <br>					
					  
					    <input type="submit" onClick="return validateEmail();" id="submitbutton" name="submitbutton" value="Submit">
				  </p>
					<p>Before you can buy or sell on swapen you need an Amazon Payment Account. Don't have one yet, <a href="https://payments.amazon.com/sdui/sdui/index.htm">click here</a><br>
				        </p>
				</div><br>
        </form></td>
      </tr>	
    </table></td>
  </tr>
</table>
</div>